package com.huizhonglm.diap.core.location;

import android.content.SharedPreferences;

import com.alibaba.fastjson.JSON;
import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.core.storage.model.LocationInfo;
import com.huizhonglm.diap.core.storage.pref.Keys;
import com.huizhonglm.diap.core.storage.pref.Preferences;
import com.huizhonglm.diap.core.utils.LogUtil;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-06-19 13:15
 */
public class LocationUtil {

    public static LocationInfo getLocation(){
        String json  = Preferences.getInstance().getString(Keys.curLocation, "");
        LogUtil.print("LocationUtil - getLocation=" +json);
        if (!EmptyUtil.isEmpty(json)) {
            return JSON.parseObject(json, LocationInfo.class);
        }
        return null;
    }

    public static void setLocation(LocationInfo info){
        String json = JSON.toJSONString(info);
        LogUtil.print("LocationUtil - setLocation=" +json);
        SharedPreferences.Editor editor = Preferences.getInstance().edit();
        editor.putString(Keys.curLocation, json);
        editor.apply();
    }

}
